<template>
  <div class="app-container">
    <el-row>
      <el-form ref="form" :model="form" label-width="80px">
       <el-col :span="4" > <el-form-item><el-input v-model="form.input" ></el-input></el-form-item></el-col>
       <el-col :span="3"><el-form-item><el-button round  type="primary"  @click="searchfilm(form.input)">搜索</el-button></el-form-item></el-col>
        </el-form>
       <el-col :offset="8" :span="3"><el-button class="mybtn" type="danger" @click="addfilm">新增</el-button></el-col>
    </el-row>
    <el-table
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >

      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index +1}}
        </template>
      </el-table-column>
      <el-table-column label="电影图片" width="339">
        <template slot-scope="scope">
          <img :src="scope.row.nfImg" style="width: 100px;height: 120px" >
        </template>
      </el-table-column>
      <el-table-column label="电影名字" width="150" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.nfName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="导演" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.nfDirector }}</span>
        </template>
      </el-table-column>
      <el-table-column label="演员" width="350" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.nfActor }}</span>
        </template>
      </el-table-column>

      <el-table-column label="电影时长" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.nfLongtime }}
        </template>
      </el-table-column>

      <el-table-column label="价格" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.nfPrice }}
        </template>
      </el-table-column>


      <el-table-column class-name="status-col" label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button  @click="remove(scope.row.id)" >删除</el-button><el-button   @click="change(scope.row.nfId)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination  v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
  import Qs from "qs"
import Pagination from '@/components/Pagination/index'
export default {
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      input:'',
      total: 0,
      bkcolor: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      list: [{
        id:0,nfId:1,nfName:'',nfDirector:'',nfActor:'',nfLongtime:'', nfPrice:20,nfImg:''
      }],
      form:{input:''}
    }
  },
  created() {
    this.getList()
  },

  methods: {

    searchfilm(nfName){
      var vm =this
      this.axios({
        url:'http://localhost:80/api/nextfilm/nameis/',
        params:{nfName}
      }).then(function(res) {
        if(res.data.success){
          vm.list=res.data.data
        }
      })
    },

    addfilm(){
      this.$router.push('/next/addnextfilm')
    },
    getList() {
      var vm = this
      this.axios({
        url: 'http://localhost:80/api/nextfilm/getAllfilms?pageNum='+vm.listQuery.page+"&pageSize="+vm.listQuery.limit
        //url:'http://localhost:80/api/nextfilm/getfilms'
      }).then(function(res) {
        if (res.data.success) {
          vm.total = res.data.data.total
          console.log(res.data.data)
          vm.list = res.data.data.list
        }
      })
    },
    change(nfId){
      console.log("ID值为"+nfId)
      this.$router.push({name:'changefilm',params:{nfId}})
    } ,
    remove(id){
      var vm =this
      this.$confirm('此操作将永久删除该电影, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios({
          url:'http://localhost:80/api/nextfilm/removefilm',
          method:'post',
          transformRequest: [function (data) {
            return Qs.stringify(data)
          }],
          data:{id:id}
        }).then(function(res) {
          if(res.data.success){
            vm.$message('成功!')
            console.log(res.data)
            vm.getList();
          } else{
            vm.$message('失败!')
          }

        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  }
}
</script>
